package com.winz.cultureapp.activity;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.winz.cultureapp.R;
import com.winz.cultureapp.base.BaseAppCompatActivity;
import com.winz.cultureapp.constants.Constants;
import com.winz.cultureapp.entity.UserInfoBean;
import com.winz.cultureapp.http.OnResponeListener;
import com.winz.cultureapp.http.util.HttpUitls;
import com.winz.cultureapp.utils.JsonUtil;
import com.winz.cultureapp.utils.Logger;
import com.winz.cultureapp.utils.SharePrefsUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 我的认证
 */
public class CertificationActivity extends BaseAppCompatActivity {
    @BindView(R.id.tv_top_title)
    TextView mTv_top_title;
    @BindView(R.id.tv_name)
    TextView mTv_name;
    @BindView(R.id.tv_volunteer)
    TextView mTv_volunteer;
    @BindView(R.id.rl_name)
    RelativeLayout mRl_name;

    @Override
    protected int contentView() {
        return R.layout.activity_certification;
    }

    @Override
    protected void initViews() {
        setStatusBar(getResources().getColor(R.color.base_color));
        mTv_top_title.setText(getString(R.string.mine_top_item1));
        mRl_name.setClickable(false);
    }

    private void getList() {
        showProgressDialog();
        HttpUitls.onGet("user_info", SharePrefsUtil.getInstance().getString(Constants.USER_INFO.TOKEN),new OnResponeListener<UserInfoBean>() {
            @Override
            public void onSuccess(UserInfoBean bean) {
                Logger.d("user_info==>>", JsonUtil.getJsonFromObj(bean));

                HttpUitls.isExpire(bean.code);
                if (bean.code == 0) {
                    if (bean.data.authStatus ==0){
                        if (bean.data.authApplyStatus == 0){
                            // 未申请
                            mTv_name.setText("未认证");
                            mRl_name.setClickable(true);
                            mTv_name.setTextColor(getResources().getColor(R.color.base_color));
                        }else if(bean.data.authApplyStatus == 1) {
                            // 申请中待审批
                            mTv_name.setText("审核中");
                            mRl_name.setClickable(false);
                            mTv_name.setTextColor(getResources().getColor(R.color.chocolate));
                        }else if (bean.data.authApplyStatus == 2){
                            // 审批通过
                            mTv_name.setText("已认证");
                            mTv_name.setTextColor(getResources().getColor(R.color.dodgerblue));
                        }else {
                            // 审批不通过
                            mTv_name.setText("认证失败");
                            mRl_name.setClickable(true);
                            mTv_name.setTextColor(getResources().getColor(R.color.icon_red));
                        }
                    }else{
                        // 已认证
                        mTv_name.setText("已认证");
                        mTv_name.setTextColor(getResources().getColor(R.color.dodgerblue));
                    }
                }else{
                    showMsg(bean.msg);
                }
                dismissProgressDialog();
            }

            @Override
            public void onFailed(String error) {
                Logger.d("user_info==>>", error);
                dismissProgressDialog();
            }
        });
    }

    @OnClick({R.id.fl_back, R.id.rl_name, R.id.rl_volunteer,R.id.rl_organization})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fl_back:
                finish();
                break;
            case R.id.rl_name: // 实名认证
                startActivity(RealNameAuthenActivity.class,false);
                break;
            case R.id.rl_volunteer: // 志愿者认证
                showMsg("此功能正在筹备中，敬请期待");
//                startActivity(RegisterVolunteerActivity.class,false);
                break;
            case R.id.rl_organization: // 志愿者管理员认证
                showMsg("此功能正在筹备中，敬请期待");
//                startActivity(VolunteerAdminActivity.class,false);
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        getList();
    }
}
